﻿#include "search_box_widget.h"
#include "ui_search_box_widget.h"

SearchBoxWidget::SearchBoxWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::SearchBoxWidget)
{
    initUi();
    initData();
    initUiData();
    initConnect();
}

SearchBoxWidget::~SearchBoxWidget()
{
    delete ui;
}

void SearchBoxWidget::initUi()
{
    ui->setupUi(this);

    choose = ui->opation;
    input_box = ui->input_box;
}

void SearchBoxWidget::initData()
{

}

void SearchBoxWidget::initUiData()
{

}

void SearchBoxWidget::initConnect()
{
    void(QComboBox:: *opation_change_signal)(const QString &) = &QComboBox::currentIndexChanged;
    connect(choose, opation_change_signal, [=]() {
        emit opationChange();
    });


    void(QLineEdit:: *input_box_change_signal)(const QString &) = &QLineEdit::textChanged;
    connect(input_box, input_box_change_signal, [=]() {
        emit inputTextChange(last_input_text, getInputText());
        last_input_text = getInputText();
    });
}

QString SearchBoxWidget::getOpationText()
{
    return choose->currentText();
}

void SearchBoxWidget::setInputText(const QString &input_text)
{
    input_box->setText(input_text);
}

QString SearchBoxWidget::getInputText()
{
    return input_box->text();
}
